package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.domain.DeliveryDetail;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Check;
import com.ruoyi.system.service.ICheckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 验收Controller
 *
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/system/check")
public class CheckController extends BaseController {
    @Resource
    private ICheckService checkService;

    /**
     * 查询验收列表
     */
    //@PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(Check check) {
        startPage();
        List<Check> list = checkService.selectCheckList(check);
        return getDataTable(list);
    }

    /**
     * 查询验收统计
     */
    @GetMapping("/selectCheckDay")
    @Anonymous
    public AjaxResult selectCheckDay(Check check) {
        return AjaxResult.success(checkService.selectCheckDay(check));
    }

    /**
     * 导出验收列表
     */
    //@PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "验收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Check check) {
        List<Check> list = checkService.selectCheckList(check);
        ExcelUtil<Check> util = new ExcelUtil<Check>(Check.class);
        util.exportExcel(response, list, "验收数据");
    }

    /**
     * 获取验收详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(checkService.selectCheckById(id));
    }

    /**
     * 新增验收
     */
    //@PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "验收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryDetail req) {
        return toAjax(checkService.insertCheck(req));
    }

    /**
     * 修改验收
     */
    //@PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "验收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Check check) {
        return toAjax(checkService.updateCheck(check));
    }

    /**
     * 删除验收
     */
    //@PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "验收", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(checkService.deleteCheckByIds(ids));
    }
}
